package com.dragonsoftbravo.sqlbuilder.sql.sub;

import com.dragonsoftbravo.sqlbuilder.SqlContext;

import java.util.Arrays;


public class SqlGroupBy implements GroupBy{
	StringBuilder sqlBuilder;
	public SqlGroupBy(StringBuilder sqlBuilder) {
		this.sqlBuilder = sqlBuilder;
	}

	@Override
	public GroupByConst groupBy(String... args) {
		return groupBy(Arrays.asList(args));
	}

	@Override
	public GroupByConst groupBy(Iterable<String> args) {
		sqlBuilder.append(" GROUP BY");
		for(String arg : args){
			sqlBuilder.append(" " + SqlContext.getColumn(arg)).append(",");
		}
		sqlBuilder.delete(sqlBuilder.length()-1, sqlBuilder.length());
		return new SqlGroupByConst(sqlBuilder);
	}

}
